package common.mapstruct;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @description: TODO 类描述
 * @author: kanggw
 * @date: 2024/3/5
 **/
public class MapstuctDemo {

    public static void main(String[] args) {
        Person person = Person.builder()
                            .age(1)
                            .name("test")
                            .build();
        Student student = MapperConvertService.CONVERT_SERVICE.toStudent(person);

        Family family = Family.builder()
                             .personList(Lists.newArrayList(person))
                             .build();
        School school = MapperConvertService.CONVERT_SERVICE.toSchool(family);
        System.out.println(student);
        System.out.println(school);

    }



    //定义一个人的静态内部类
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @Accessors(chain = true)
    public static class Person{
        private String name;
        private int age;
        private String sex;

    }
    //定义一个学生的静态内部类，继承于person类
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @Accessors(chain = true)
    public static class Student{
        private String name;
        private int age;
        private String sex;
        private String school;
        private String grade;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @Accessors(chain = true)
    public static class Family{
        List<Person> personList;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @Accessors(chain = true)
    public static class School{
        List<Student> studentList;
        List<Student> studentList2;
    }


}

